<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业13</title>
    <script>
        /*
         求一组数中的最大值和最小值，以及所在位置的下标。
        */

        var arr = [5,2,1,6,3,4,];

        function getMaxAndMinNum(arr){
            var maxNum = arr[0];
            var minNum = arr[0];
            var maxNumIndex = 0;
            var minNumIndex = 0;
            
            for(var i=0; i < arr.length; i++) {
                if(maxNum < arr[i]){
                    maxNum = arr[i];
                    maxNumIndex = i;
                }
                if(minNum > arr[i]){
                    minNum = arr[i];
                    minNumIndex = i;
                }
            }

            console.log("最大数是"+maxNum+",最大数的下标是"+maxNumIndex);
            console.log("最小数是"+minNum+",最小数的下标是"+minNumIndex);
        }

        getMaxAndMinNum(arr);        

    </script>
</head>
<body>
    
</body>
</html>